import type { HttpInterceptorManagerSpec, HttpRequestInterceptor, HttpResponseInterceptor } from '@/config/httpClient/HttpInterceptor.ts'


/**
 * HTTP 拦截器管理器委托
 */
export class HttpInterceptorDelegationManager implements HttpInterceptorManagerSpec {

    private readonly managerList: Array<HttpInterceptorManagerSpec>

    constructor(managerList: Array<HttpInterceptorManagerSpec>) {
        this.managerList = managerList
    }

    addRequestInterceptor(interceptor: HttpRequestInterceptor, name: string): void {
        this.managerList.forEach(manager => manager.addRequestInterceptor(interceptor, name))
    }

    addResponseInterceptor(interceptor: HttpResponseInterceptor, name: string): void {
        this.managerList.forEach(manager => manager.addResponseInterceptor(interceptor, name))
    }

    removeRequestInterceptor(name: string): void {
        this.managerList.forEach(manager => manager.removeRequestInterceptor(name))
    }

    removeResponseInterceptor(name: string): void {
        this.managerList.forEach(manager => manager.removeResponseInterceptor(name))
    }

}
